import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  { path: '/login',name:'login', component: () => import('@/views/user/login/index'), hidden: true },
  { path: '/register',name:'register', component: () => import('@/views/user/register/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true},
  {
    path: '/',
    component: Layout,
    redirect: '/news/newsRelease',
 /*   children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'dashboard'}
    }]*/
  },
  {
    path: '/news',
    component: Layout,
    meta: {title: '新闻管理', icon: 'newsRelease'},
    children: [{
      path: 'newsRelease',
      name: 'newsRelease',
      component: () => import('@/views/newsRelease/index'),
      meta: {title: '新闻发布', icon: 'newsRelease'},
    }, {
      path: 'newsAdd',
      name: 'newsAdd',
      hidden: true,
      component: () => import('@/views/newsRelease/components/newsAdd'),
      meta: {title: '新闻添加', icon: 'newsRelease'}
    }, {
      path: 'newsExamine',
      name: 'newsExamine',
      hidden: true,
      component: () => import('@/views/newsRelease/components/NewsExamine'),
      meta: {title: '新闻审核', icon: 'newsRelease'}
    }]
  }, {
    path: '/announcementDynamics',
    component: Layout,
    meta: {title: '公告管理', icon: 'announcementDynamics'},
    children: [{
      path: 'announcementDynamics',
      name: 'announcementDynamics',
      component: () => import('@/views/announcementDynamics/index'),
      meta: {title: '公告发布', icon: 'announcementDynamics'},
    }, {
      path: 'announcementAdd',
      name: 'announcementAdd',
      hidden: true,
      component: () => import('@/views/announcementDynamics/components/newsAdd'),
      meta: {title: '公告添加', icon: 'newsRelease'}
    }, {
      path: 'announcementExamine',
      name: 'announcementExamine',
      hidden: true,
      component: () => import('@/views/announcementDynamics/components/NewsExamine'),
      meta: {title: '公告审核', icon: 'newsRelease'}
    }]
  }, {
    path: '/department',
    component: Layout,
    meta: {title: '科室管理', icon: 'department'},
    children: [{
      path: 'department',
      name: 'department',
      component: () => import('@/views/department/index'),
      meta: {title: '科室列表', icon: 'department'},
    }, {
      path: 'departmentAdd',
      name: 'departmentAdd',
      hidden: true,
      component: () => import('@/views/department/components/departmentAdd'),
      meta: {title: '科室添加', icon: 'departmentAdd'}
    }, {
      path: 'doctor',
      name: 'doctor',
      component: () => import('@/views/doctor/index'),
      meta: {title: '医生管理', icon: 'doctor'}
    }, {
      path: 'doctorAdd',
      name: 'doctorAdd',
      hidden: true,
      component: () => import('@/views/doctor/components/doctorAdd'),
      meta: {title: '医生添加', icon: 'doctorAdd'}
    }]
  },
  {
    path: '/video',
    component: Layout,
    meta: {title: '视频管理', icon: 'video'},
    children: [{
      path: 'video',
      name: 'video',
      component: (resolve) => require(['../views/video/index'], resolve),
      meta: {title: '视频发布', icon: 'newsRelease'},
    }, {
      path: 'videoAdd',
      name: 'videoAdd',
      hidden: true,
      component: (resolve) => require(['../views/video/components/videoAdd'], resolve),
      meta: {title: '视频上传', icon: 'videoAdd'}
    }]
  },
  {
    path: '/leader',
    component: Layout,
    meta: {title: '领导管理', icon: 'leader'},
    children: [{
      path: 'leader',
      name: 'leader',
      component: (resolve) => require(['../views/leader/index'], resolve),
      meta: {title: '领导列表', icon: 'newsRelease'},
    }, {
      path: 'leaderAdd',
      name: 'leaderAdd',
      hidden: true,
      component: (resolve) => require(['../views/leader/components/leaderAdd'], resolve),
      meta: {title: '领导添加', icon: 'leaderAdd'}
    }]
  }, {
    path: '/indexImg',
    component: Layout,
    meta: {title: '主题图片', icon: 'leader'},
    children: [{
      path: 'indexImg',
      name: 'indexImg',
      component: (resolve) => require(['../views/index/indexImg/index'], resolve),
      meta: {title: '首页图片', icon: 'newsRelease'},
    }, {
      path: 'imageAdd',
      name: 'imageAdd',
      hidden: true,
      component: (resolve) => require(['../views/index/indexImg/components/imageAdd'], resolve),
      meta: {title: '首页图片添加', icon: 'imageAdd'}
    },{
      path: 'carousel',
      name: 'carousel',
      component: (resolve) => require(['../views/index/carousel/index'], resolve),
      meta: {title: '轮播图片', icon: 'newsRelease'},
    }, {
      path: 'carouselAdd',
      name: 'carouselAdd',
      hidden: true,
      component: (resolve) => require(['../views/index/carousel/components/imageAdd'], resolve),
      meta: {title: '轮播图添加', icon: 'imageAdd'}
    }, {
      path: 'environment',
      name: 'environment',
      component: (resolve) => require(['../views/index/environment/index'], resolve),
      meta: {title: '医院环境图片', icon: 'newsRelease'},
    }, {
      path: 'environmentAdd',
      name: 'environmentAdd',
      hidden: true,
      component: (resolve) => require(['../views/index/environment/components/imageAdd'], resolve),
      meta: {title: '医院环境图片添加', icon: 'imageAdd'}
    },]
  },

// 404 页面
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  mode: 'history', // 需要服务支持
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes,
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
